package pl.planito.company.manager;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.model.SelectItem;

import pl.planito.exceptions.InventoryEditException;
import pl.planito.util.DataOperations;

public class CompanyBean extends CompanyBridge implements DataOperations {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1628026807923345100L;
	@EJB
	private ICompanyEditorLocal companyEditor;
	private List<CompanyBridge> companies;
	private List<SelectItem> companiesSI;

	public List<SelectItem> getCompaniesSI() {
		for (CompanyBridge bridge : this.companies) {
			this.companiesSI.add(new SelectItem(bridge, bridge.getName()));
		}
		return companiesSI;
	}

	public List<CompanyBridge> getCompanies() {
		return companies;
	}

	public void setCompanies(List<CompanyBridge> company) {
		this.companies = company;
	}

	public void save() {
		try {
			companyEditor.addCompany(this);
		} catch (InventoryEditException e) {
			e.printStackTrace();
		}

	}

	public void edit() {
		// TODO Auto-generated method stub

	}

	public String allCompanies() {

		try {
			this.companies = companyEditor.getAllCompanies();
			return "users";
		} catch (InventoryEditException e) {
			e.printStackTrace();
		}
		return null;
	}

}
